package com.sphd.beautysalon.model;


import com.android.volley.VolleyError;
import com.sphd.beautysalon.info.JiFenGiveInfo;
import com.sphd.beautysalon.interfaces.VolleyJsonObjectCallBack;
import com.sphd.beautysalon.presenter.ConsumeJifenPresenterImpl;
import com.wzh.frame.utils.JsonUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
* Created by Hu on 2016/12/22
*/

public class ConsumeJifenModelImpl implements ConsumeJifenModel {

    @Override
    public void sendUrl(String url, ConsumeJifenPresenterImpl consumeJifenPresenter) {
        volleyUtil.setJsonObjectRequest(url, new VolleyJsonObjectCallBack() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    List<JiFenGiveInfo> jiFenGiveInfoList = JsonUtil.getListFromString(response.getString("res"),JiFenGiveInfo.class);
                    consumeJifenPresenter.recList(jiFenGiveInfoList);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onErrorResponse(VolleyError error) {
                consumeJifenPresenter.sendError(error);
            }
        });
    }

    @Override
    public void setUrl(String url, ConsumeJifenPresenterImpl consumeJifenPresenter) {
        volleyUtil.setJsonObjectRequest(url, new VolleyJsonObjectCallBack() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    int res=response.getInt("res");
                    consumeJifenPresenter.sendRes(res);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onErrorResponse(VolleyError error) {
                consumeJifenPresenter.sendError(error);
            }
        });
    }
}